import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Product from '../components/initial_value/product.vue'
import Storehouse from '../components/initial_value/storehouse.vue'
import Supplier from '../components/initial_value/supplier.vue'
import Location from '../components/initial_value/location.vue'
import Purchase from '../components/instorehouse/purchase.vue'
import Receiving from '../components/instorehouse/receiving.vue'
import ReceivingManagement from '../components/instorehouse/receivingManagement.vue'
import Shelves from '../components/storehouseManage/shelves.vue'
import PutIn from '../components/instorehouse/putIn.vue'
import ShelvesManagement from '../components/storehouseManage/shelvesManage.vue'
import PutInManagement from '../components/instorehouse/putInManagement.vue'
import Remove from '../components/storehouseManage/remove.vue'
import RemoveManagement from '../components/storehouseManage/removeManagement.vue'
import Stock from '../components/stockManagement/stock.vue'
import OutOrder from '../components/outStorehouseManagement/outStorehouseOrder.vue'
import Picking from '../components/outStorehouseManagement/picking.vue'
import PickingManagement from '../components/outStorehouseManagement/pickingManagement.vue'

Vue.use(VueRouter)

const routes = [
  { path: '/login', component: Login },
  { path: '/', redirect: '/login' },
  // {path: '/',redirect:'/home'},
  {
    path: '/home',
    component: Home,
    redirect: '/product',
    children: [
      { path: '/product', component: Product },
      { path: '/storehouse', component: Storehouse },
      { path: '/supplier', component: Supplier },
      { path: '/location', component: Location },
      { path: '/order', component: Purchase },
      { path: '/receiving', component: Receiving },
      { path: '/receivingManagement', component: ReceivingManagement },
      { path: '/shelves', component: Shelves },
      { path: '/putin', component: PutIn },
      { path: '/shelvesManagement', component: ShelvesManagement },
      { path: '/putInManagement', component: PutInManagement },
      { path: '/remove', component: Remove },
      { path: '/removeManagement', component: RemoveManagement },
      { path: '/stock', component: Stock },
      { path: '/outOrder', component: OutOrder },
      { path: '/pick', component: Picking },
      { path: '/pickManagement', component: PickingManagement }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router

router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  // 2.获取token信息
  const token = window.sessionStorage.getItem('token')
  // 3.判断token是否有数据??  if(token) 如果token不为null
  // 如果token为null 则跳转到登录页面
  if (!token) return next('/login')
  // 表示放行
  next()
})
